﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;

/// <summary>
/// InfoDao 的摘要说明
/// </summary>
public class InfoDao
{
    //获取数据库连接串
    private static string connstr = System.Configuration.ConfigurationManager.ConnectionStrings
         ["MySQLConnectionString"].ConnectionString;
    /// <summary>
    /// 获取Info表中所有的记录
    /// </summary>
    /// <returns>数据List集合</returns>
    public static List<Info> FindAll()
    {

        List<Info> data = new List<Info>();
        
        MySqlConnection conn = new MySqlConnection(connstr);
        try
        {
            conn.Open();
            string sql = "SELECT = FROM tb_info";
            //构建一个SQL语句的命令
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            //获取数据访问的游标
            MySqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                Info info = new Info();
                info.Id = Convert.ToInt64(rdr["id"]);
                info.Title = Convert.ToString(rdr["title"]);
                info.Content = Convert.ToString(rdr["content"]);
                info.PublishTime = Convert.ToDateTime(rdr["publish_time"]);
                info.Author = Convert.ToString(rdr["author"]);
                info.ClickNumber = Convert.ToInt32(rdr["click_number"]);
                info.CategoryMark = Convert.ToString(rdr["category_mark"]);
                data.Add(info);
                


            }

            rdr.Close();
        }
        catch (MySqlException ex)
        {
            Debug.WriteLine("==========FindAll方法异常信息========");
            Debug.WriteLine(ex.Number + ":" + ex.Message);
            Debug.WriteLine("==========FindAll方法异常信息========");
            throw (ex);


        }
        finally
        {
            if (conn != null)
            {
                conn.Close();

            }
        }

        return data;

    }
}